package com.ehome.user.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;


import com.ehome.user.Adapter.MyAdapter;
import com.ehome.user.Interface.OnItemClickListener;
import com.ehome.user.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/3/6 0006.
 */

public class FoundFragment extends Fragment {

    @Bind(R.id.recyclerView)
    RecyclerView mRecyclerView;
    private List<String> mData = new ArrayList();
    private String[] titles = {"活动", "直播", "新手课堂", "帮助中心", "平台介绍", "公司新闻"};
    private MyAdapter mAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.tab_found_fragment, container, false);
        ButterKnife.bind(this, view);
        setadapter();
        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    private void setadapter() {
        mData.clear();
        for (int i = 0; i < titles.length; i++) {
            mData.add(titles[i]);
        }
        mRecyclerView.setFocusable(false);
        mRecyclerView.setNestedScrollingEnabled(false);
        mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(),3));
        mAdapter = new MyAdapter(getActivity(), mData);
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setOnClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view) {
                int position = mRecyclerView.getChildAdapterPosition(view);
                Toast.makeText(getActivity(), mData.get(position), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onItemLongClick(View view) {
                int position = mRecyclerView.getChildAdapterPosition(view);
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
